<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客主页</title>
    <link rel="stylesheet" href="css/list.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <script src="js/common.js"></script>
    <script src="js/jquery.min.js"></script>

    <style>

        .nav{
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 50px;
        }
        .container{
            padding-top: 80px;
            height: auto;
        }
        .container-right{
            width: auto;
        }
        .blog-pagnation-wrapper{
            height: 40px;
            margin: 16px 0;
            text-align: center;
        }
        .blog-pagnation-item{
            display: inline-block;
            padding: 8px;
            border: 1px solid #d0d0d5;
            color: #333;
        }
        .blog-pagnation-item:hover{
            background: #4e4eeb;
            color: #fff;
        }
        .blog-pagnation-item.actvie{
            background: #4e4eeb;
            color: #fff;
        }

    </style>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/system.png" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="login.html">登录</a>
        <a href="reg.html">注册</a>
    </div>
    <!-- 版心 -->
    <div class="container">
        <div class="container-right" style="width: 100%;">
            <div id="artListDiv">
            </div>
            <hr>
            <div class="blog-pagnation-wrapper">
                <button onclick="getFifstPage()" class="blog-pagnation-item">首页</button> 
                <button onclick="getBeforePage()" class="blog-pagnation-item">上一页</button>  
                <button onclick="getNextPage()" class="blog-pagnation-item">下一页</button>
                <button onclick="getLastPage()" class="blog-pagnation-item">末页</button>
            </div>
        </div>
    </div>

    <script>
        // 当前页码
        var pindex = 1;
        // 博客列表每页显示数目
        var psize = 2; 
        // 最大的页数
        var pcount = 1;
        
        pindex = (getUrlValue("pindex")==""?1:getUrlValue("pindex"));
        function initPage() {
            jQuery.ajax({
                url: '/art/listpage',
                type: 'post',
                data: {"pindex": pindex, "psize": psize},
                success: function(result) {
                    if (result != null && result.statusCode == 200 && result.data.list.length > 0) {
                        var artListHtml = "";
                        for (var i = 0; i < result.data.list.length; i++) {
                            var articleinfo = result.data.list[i];
                            artListHtml += '<div class="blog">';
                            artListHtml += '<div class="title">' + articleinfo.title + '</div>';
                            artListHtml += '<div class="date">' + articleinfo.updatetime + '</div>';
                            artListHtml += '<div class="desc">' + articleinfo.content + '</div>';
                            artListHtml += '<a href="blog_content.html?id=' + articleinfo.id 
                            + '" class="detail">查看全文 &gt;&gt;</a>';
                            artListHtml += '</div>';
                        }
                        jQuery("#artListDiv").html(artListHtml);
                        pcount = result.data.pcount;
                    }
                }
            });
        }

        initPage();

        function getFifstPage() {
            if (pindex <= 1) {
                alert("已经在首页了！");
                return;
            }
            location.href = "blog_list.html";
        }

        function getBeforePage() {
            if (pindex <= 1) {
                alert("已经在首页了！");
                return;
            }
            pindex = parseInt(pindex) - 1;
            location.href = "blog_list.html?pindex=" + pindex;
        }
        
        function getNextPage() {
            if (pindex >= pcount) {
                alert("后面已经没有内容了哦~");
                return;
            }
            pindex  = parseInt(pindex) + 1;
            location.href = "blog_list.html?pindex=" + pindex;
        }

        function getLastPage() {
            if (pindex >= pcount) {
                alert("已经在末页了！");
                return;
            }
            pindex = pcount;
            location.href = "blog_list.html?pindex=" + pindex;
        }
    </script>
</body>
</html>